package com.jp.knowledge.view;

import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.jp.knowledge.R;
import com.jp.knowledge.adapter.skill.PositionKnolegeContentAdapter;
import com.jp.knowledge.adapter.skill.SkillContentAdapter;
import com.jp.knowledge.model.PositionKnowlegeMode;
import com.jp.knowledge.model.SkillModel;
import com.jp.knowledge.my.base.RecycleVAdapter;

import java.util.ArrayList;

/**
 * Created by 528787067@qq.com on 2017/4/20.
 */

public class SkillContentView extends FrameLayout {

    private Context mContext;
    private TextView title;
    private View line;
    private JpRecycleView mainView;
    private PositionKnolegeContentAdapter adapter;
    private PositionKnowlegeMode.ListBeanX data;
    private int mainPosition;

    public SkillContentView(Context context) {
        this(context,null);

    }

    public SkillContentView(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public SkillContentView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mContext = context;
        View contentView = View.inflate(mContext, R.layout.skill_content_view, this);
        title = (TextView) contentView.findViewById(R.id.skill_content_title);
        mainView = (JpRecycleView) contentView.findViewById(R.id.skill_content_view);
        line =contentView.findViewById(R.id.line);
        mainView.setLayoutManager(new GridLayoutManager(mContext, 3){
            @Override
            public boolean canScrollVertically() {
                return false;
            }
            @Override
            public boolean canScrollHorizontally() {
                return false;
            }
        });
        mainView.setHasFixedSize(true);
        adapter = new PositionKnolegeContentAdapter(mContext, null);
        mainView.setAdapter(adapter);
        adapter.addItemClickListener(new RecycleVAdapter.OnItemClickListener() {
            @Override
            public void itemSelect(int position) {
                if(onItemClickListener != null)
                    onItemClickListener.onItemClick(mainPosition, position);
            }
        });
    }

    public void setData(PositionKnowlegeMode.ListBeanX data, int position){
        if(data == null)
            return;
        this.mainPosition = position;
        this.data = data;
        title.setText(this.data.getName());
        adapter.updateAdapter(this.data.getList());
    }

    public void hideLine(){
        line.setVisibility(View.GONE);
    }


    private OnItemClickListener onItemClickListener;
    public void setOnItemClickListener(OnItemClickListener itemClickListener){
        this.onItemClickListener = itemClickListener;
    }
    public interface OnItemClickListener{
        void onItemClick(int mainPosition, int subPosition);
    }
}
